mixin tournamentTileMixin(tournament)
  - var showLink = false
  // show link when tournament starting/ended or in 1 day to start
  if tournament.state == 'initializing'
    - now = new Date().getTime()
    - twoHours = 2*60*60*1000
    - tournamentStart = new Date(tournament.startDate).getTime()
    - timeLeft = (((tournamentStart - now)/twoHours) + 0.99)|0
    if timeLeft <= 1
      - showLink = true
  else
    - showLink = true
  - var showLadderImage = tournament.state != 'initializing' && view.ladderImageMap[tournament.levelOriginal]

  a.ai-league-btn.tile(href=showLink ? `/play/ladder/${tournament.slug}/clan/${tournament.clan}?tournament=${tournament._id}`: 'javascript: window.alert("Tournament not started yet")', title=tournament.description)
    // do not show preview image for initializing tournaments
    if showLadderImage
      img.level-image(src=view.ladderImageMap[tournament.levelOriginal], alt=tournament.name).img-rounded
    else
      img.level-image(src="/images/pages/play/ladder/multiplayer_notext.jpg", alt=tournament.name).img-rounded
      h3.dynamic-level-name.overlay-text= tournament.displayName
    .tile-text-backdrop
    .stats-text-container
      .overlay-text.stats-text
        if showLadderImage
          span= tournament.displayName || tournament.name
        else
          span= tournament.name
    .play-text-container
      .overlay-text.play-text
        if tournament.state == 'initializing'
          - now = new Date().getTime()
          - time = (new Date(tournament.startDate).getTime() - now)/(24*3600*1000)|0
          span(data-i18n="tournament.estimate_days", data-i18n-options={time})
        else if tournament.state == 'starting'
          span(data-i18n="courses.play_tournament")
        else if tournament.state == 'ended'
          span(data-i18n="tournament.view_results")
